#ifndef CHATLISTVIEW_H
#define CHATLISTVIEW_H

#include <QListView>
#include <QObject>
#include <QTextEdit>
#include <QPainter>
#include <QStyledItemDelegate>
#include <QKeyEvent>
#include <QFileDialog>
#include <QLabel>
#include <QMenu>

// 重写聊天页面的ListView、QStyledItemDelegate、QSortFilterProxyModel类

// 重写聊天页面的ListView
class ChatListView : public QListView
{
    Q_OBJECT
public:
    ChatListView(QWidget *parent = nullptr);

protected:
    // 重写右键菜单事假
    void contextMenuEvent(QContextMenuEvent *event);
signals:
    void menuChoice(QModelIndex index);
};



// 重写聊天页面的QStyledItemDelegate
// Qt::UserRole：1(头像)/2(名字)/3(未读消息)/4(项的名字)/5(上一次聊天记录)
class ChatItemDelegate: public QStyledItemDelegate
{
    Q_OBJECT
public:
    ChatItemDelegate(QWidget* parent = nullptr);
    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void paint(QPainter* painter,const QStyleOptionViewItem& option,const QModelIndex& index) const;
};


// 重写实现回车发送消息，Ctrl+回车换行的TextEdit
class MyTextEdit : public QTextEdit
{
    Q_OBJECT
public:
    MyTextEdit(QWidget* parent = nullptr);
protected:
    void keyPressEvent(QKeyEvent *event) override;
signals:
    void keyForSendMsg();
};


// 重写聊天页面中的头像QLabel的点击事件
class ChatAvatarLabel : public QLabel
{
    Q_OBJECT
public:
    ChatAvatarLabel(QWidget* parent = nullptr);
protected:
    void mousePressEvent(QMouseEvent* event) override;
signals:
    void chatAvatarLabelClicked(QString id);
};

// 重写聊天页面中的图片消息点击事件
class PhotoLabel : public QLabel
{
    Q_OBJECT
public:
    PhotoLabel(QWidget* parent = nullptr);
protected:
    void mousePressEvent(QMouseEvent* event) override;
signals:
    void showAPhoto(QPixmap pixmap);
};

#endif // CHATLISTVIEW_H
